[PGS] 올바른 괄호 - #79
Open
been12151 wants to merge 16 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🍪 문제 이름
Resolve: 올바른 괄호
🍊 문제 정의
inputs:(또는)로만 이루어진 문자열 (1 ≤ 길이 ≤ 100,000)outputs가 올바른 괄호 문자열이면True, 아니면False예시
🍑 알고리즘 설계
스택을 활용. 문자를 순서대로 읽으면서 스택이 비어 있거나 현재 문자가
(이면 스택에 push. 스택의 top이(이고 현재 문자가)이면 짝이 맞으므로 pop.모든 문자를 처리한 후 스택이 비어 있으면 올바른 괄호, 남아 있으면 짝이 맞지 않는 괄호가 있다는 뜻이므로
not stack으로 바로 반환.🥝 최악 수행 시간 복잡도
O(n)(n = s의 길이)🍰 특이 사항 (Optional)
not stack으로 bool을 바로 반환하는 부분에서, 스택에(만 들어갈 수 있는 구조라 top이(인지 별도로 체크할 필요 없이 비어 있는지 여부만 확인하면 됨.